﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ClassLibrary.Entity;
using ClassLibrary.DAO;
using System.IO;

public partial class en_ucControl_ManagerPhotos : System.Web.UI.UserControl
{
    TblAccountsDAO AccountDAO = new TblAccountsDAO(Global.CONNECTION_STRING);
    TblImagesDAO ImageDAO = new TblImagesDAO(Global.CONNECTION_STRING);
    TblAlbumImagesDAO AlbumDAO = new TblAlbumImagesDAO(Global.CONNECTION_STRING);
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session[Global.SESSION_LOGGED_USER] != null)
            {
                LoadCountry();
                LoadAccountInfor();
                LoadImagebyIDAcc();
            }
            else
                Response.Redirect("~/en/Default.aspx");
        }
    }
    private void LoadImagebyIDAcc()
    {
        int IDAcc = ((TblAccounts)Session[Global.SESSION_LOGGED_USER]).IDAcc;

        DataTable dt = AlbumDAO.GetAlbumsByIDAcc(IDAcc);

        string IDAlbum = "";
        foreach (DataRow dr in dt.Rows)
        {
            IDAlbum = dr["IDAlbum"].ToString();
        }
        if (IDAlbum == "" || IDAlbum == null)
        {
            Response.Redirect("~/en/Upload.aspx");
        }
        else
        {
            DataTable dt1 = ImageDAO.GetImageByIdAlbum(Convert.ToInt32(IDAlbum));
            reImageByAlbum.DataSource = dt1;
            reImageByAlbum.DataBind();

            foreach (DataRow dr1 in dt.Rows)
            {
                lblAlbumName.Text = dr1["AlbumName"].ToString();
            }
        }
        hypGetPhotoGroup.NavigateUrl = "~/en/GetCodePhotosGroups.aspx?IdAl=" + IDAlbum + "&keepThis=true&TB_iframe=true&width=700&height=450&ico=images/Get.png";
    }

    private void LoadAccountInfor()
    {
        int IDAcc = ((TblAccounts)Session[Global.SESSION_LOGGED_USER]).IDAcc;
        TblAccounts Account = AccountDAO.GetAccountById(IDAcc);
        txtUsername.Text = Account.UsernameAcc;
        txtEmail.Text = Account.EmailAcc;
        txtFName.Text = Account.FirstName;
        txtLName.Text = Account.LastName;
        txtPhone.Text = Account.PhoneNumber;
        drcountry.SelectedItem.Text = Account.Country;
    }
    private void LoadCountry()
    {
        DataSet DSSCountry = new DataSet();
        DSSCountry.ReadXml(Server.MapPath("../App_Data/countries.xml"));
        drcountry.DataSource = DSSCountry;
        drcountry.DataTextField = "name";
        drcountry.DataValueField = "code";
        drcountry.DataBind();
    }

    
}
